<html>
<!-- Use template-cell in field to define cell template.
 All fields from query could be used in template for any cell using {{FIELD}} form.
-->
<style>
 {{{defaultstyle}}}
 body {margin: 20px 20px}
 td, th {border: solid #eee 1px; font-size: 12px; padding: 2 2; }
 th {background: #888; color: white; padding: 5px 5px; resize: horizontal; draggable: true; }
 .table-group-box {background: #888; border: solid #555 1px; padding: 3 3; margin: 5 0; color: white }
 .group {background: #686; font-weight: bold; font-size: 16px; color: white}

</style>

<h2>Customer list</h2>
<i>Company column has hint containing company orders</i>
<br><br>
<div>
<DATAPACKET>
 <METADATA header="true" autosort="true">
  <FIELDS>
   <FIELD name="CUSTNO" caption="No"/>
   <FIELD name="COMPANY" caption="Company">
    <template-cell>
     <div title="<style>  td, th {border: solid #888 1px; color: black}</style><h2>{{COMPANY}}</h2>{{detail}}">
     {{COMPANY}}
     </div>
    </template-cell>
   </FIELD>
   <FIELD name="STATE" caption="Address">
    <template-cell>
     {{ADDR1}}, <b>{{CITY}}</b>, {{STATE}}
    </template-cell>
   </FIELD>
   <FIELD name="CONTACT" caption="Contact">
    <template-cell>
    {{CONTACT}} (<i>{{PHONE}})</i>
    </template-cell>
   </FIELD>
  </FIELDS>
  <SQL>
   select c.* from customer c
  </SQL>
 </METADATA>
  <template-table>
  <![CDATA[
    <table {{{attributes}}}>
     {{{header}}}{{{body}}}
    </table>
   ]]>
  </template-table>
  <template-row custom="true">
  <![CDATA[
   <tr a=1{{{attributes}}}>
   {{{_text}}}
   </tr>
   ]]>
  </template-row>

 <DETAIL id="orders" width="900" style="color: white; border-collapse: collapse;  margin: 10 10" >
  <METADATA>
   <FIELDS>
    <FIELD name="ORDERNO" caption="Order No" group_template="@COMPANY@" total="count(*)" width="10%"/>
    <FIELD name="SALEDATE" caption="Sale Date" width="10%"/>
    <FIELD name="SHIPDATE" caption="Ship Date" width="10%"/>
    <FIELD name="LASTNAME" caption="Employee" width="20%"/>
    <FIELD name="PAYMENTMETHOD" caption="Payment Method" align="center" width="20%"/>
    <FIELD name="ITEMSTOTAL" caption="Total" total="sum" format="# ### ###.00" width="15%"/>
    <FIELD name="AMOUNTPAID" caption="Amount Paid" total="sum" format="# ### ###.00" width="15%"/>
   </FIELDS>
   <SQL>
    select o.orderno, cast(saledate as date) saledate, cast(shipdate as date) shipdate,
     paymentmethod, itemstotal, amountpaid, e.lastname
    from orders o
    join employee e on e.empno=o.empno
    where custno=:custno
    order by 1
   </SQL>
  </METADATA>
 </DETAIL>


</DATAPACKET>
</div>

</html>
